// pages/impression/detail/detail.js
const http = require("../../../utils/http.js")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    impression: {},
    imgList: [],

    version: '1.0.0'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    http.get("/get")
      .then(res => {
        this.setData({
          version: res.data
        })
      })

    let impressionId = options.id
    let that = this;
    // let impressionId = 3
    http.get("/impression/getDetail", {
      impressionId: impressionId
    }).then(res=>{
      let impressionData = res.data.data
      impressionData.impression.grade = parseInt(impressionData.impression.grade)

      
      if (impressionData.file != null){
        let list = []
        for (let i = 0; i < impressionData.file.length; i++){
          list.push(impressionData.file[i].fileUrl)
        }
        that.setData({
          imgList: list
        })
      }
      that.setData({
        impression: impressionData
      })
    })
  },
  ViewImage(e) {
    wx.previewImage({
      urls: this.data.imgList,
      current: e.currentTarget.dataset.url
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})